//
//  DataCompareType.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/3.
//

import UIKit
import MYModule

public enum SleepDataCompareType {
//    case graterStep(index:Int, percentage:Int)         //比--的同类用户走得多
    case graterEarlySleep(index:Int, percentage:Int)   //比--的同类用户睡得早
    case graterEarlyAwake(index:Int, percentage:Int)   //比--的同类用户起得早
    case lessSleep(index:Int, percentage:Int)          //比--的同类用户睡得少
    
    public func titleAttributedText(normarPercentStr: String?) -> NSAttributedString {
        var content = ""
        var percentStr = ""
       
        switch self {

        case .graterEarlySleep(_,let percentage):
            if let normarPercentStr = normarPercentStr, percentage == 0 {
                percentStr = "\(normarPercentStr)%"
            } else {
                percentStr = "\(percentage)%"
            }
            content = "sleep_sleep_early".language(with: [percentStr])
            break
        case .graterEarlyAwake(_,let percentage):
            if let normarPercentStr = normarPercentStr, percentage == 0 {
                percentStr = "\(normarPercentStr)%"
            } else {
                percentStr = "\(percentage)%"
            }
            content = "sleep_get_up_early".language(with: [percentStr])
            break
        case .lessSleep(_,let percentage):
           
            if let normarPercentStr = normarPercentStr, percentage == 0 {
                percentStr = "\(normarPercentStr)%"
            } else {
                percentStr = "\(percentage)%"
            }
            content = "sleep_less_sleep".language(with: [percentStr])
            break
        }
        
        return content.toAttributed
            .foregroundColor(UIColor.assist_000000)
            .font(Fonts.systemFont(ofSize: 16))
            .font(Fonts.systemFont(ofSize: 20), range: (content as NSString).range(of: percentStr))
            .rawValue
    }
    
    public func subTitleAttributedText(text: String, textColor: UIColor, font: UIFont) ->NSAttributedString {
        
        return text.toAttributed
            .foregroundColor(textColor)
            .font(font)
            .rawValue
    }
    
    public var highlightIndex: Int {
        switch self {
       
        case .graterEarlySleep(let index, _):
            return index
        case .graterEarlyAwake(let index, _):
            return index
        case .lessSleep(let index, _):
            return index
        }
    }
    
    public var barHightLightColor: UIColor {
        switch self {
        
        case .graterEarlySleep(_, _),.graterEarlyAwake(_, _),.lessSleep(_, _):
            return UIColor.Sleep.theme
        }
    }
    
    public var barNormalColor: UIColor {
        switch self {
        
        case .graterEarlySleep(_, _),.graterEarlyAwake(_, _),.lessSleep(_, _):
            return UIColor.Sleep.theme.withAlphaComponent(0.2)
        }
    }
    
    public var backgroundColor:UIColor{
        switch self {
        
        case .graterEarlySleep(_, _),.graterEarlyAwake(_, _),.lessSleep(_, _):
            return UIColor.background
        }
    }
    
    public var xAxisLabelColor:UIColor{
        switch self {
        
        case .graterEarlySleep(_, _),.graterEarlyAwake(_, _),.lessSleep(_, _):
            return UIColor.Sleep.theme
        }
    }
    
    public var xAxisLabelTextColor:UIColor{
        switch self {
        
        case .graterEarlySleep(_, _),.graterEarlyAwake(_, _),.lessSleep(_, _):
            return UIColor.assist_A9A9A9
        }
    }
    
   
    public var data:[Int] {
        switch self {

        case .graterEarlySleep(let index, let percentage):
            if index == 0 && percentage == 0 {
                return  [0,0,0,0,0,0,0]
            }
            return  [20,35,50,100,80,60,40]
        case .graterEarlyAwake(let index, let percentage):
            if index == 0 && percentage == 0 {
                return  [0,0,0,0,0,0,0]
            }
            return [20,30,85,100,55,40,30]
        case .lessSleep(let index, let percentage):
            
            if index == 0 && percentage == 0 {
                return  [0,0,0,0,0,0,0]
            }
            return [35,55,100,95,55,30,20]
        }
    }
    
    
    public var xAxisValues:[String]{
        switch self {
            
        case .graterEarlySleep(_, _):
            return ["<21:00","21:01\n|\n22:00","22:01\n|\n23:00","23:01\n|\n00:00","00:01\n|\n01:00","01:01\n|\n02:00",">02:01"]
        case .graterEarlyAwake(_, _):
            return ["<05:00","05:01\n|\n06:00","06:01\n|\n07:00","07:01\n|\n08:00","08:01\n|\n09:00","09:01\n|\n10:00",">10:01"]
        case .lessSleep(_, _):
            return ["<5","5-6","6-7","7-8","8-9","9-10",">10"]
        }
    }
}


